import { createApp } from "vue";

import App from "./App.vue";

import Layui from "@layui/layui-vue";
import "@layui/layui-vue/lib/index.css";

/**
 * 渲染函数
 * @returns
 */
function render() {
  const app = createApp(App);
  app.use(Layui);
  app.mount("#app");
  return app;
}

declare global {
  interface Window {
    // 是否存在无界
    __POWERED_BY_WUJIE__?: boolean;
    //对应的参数
    $wujie: any;
    // 子应用mount函数
    __WUJIE_MOUNT: () => void;
    // 子应用unmount函数
    __WUJIE_UNMOUNT: () => void;
    // 子应用无界实例
    __WUJIE: { mount: () => void };
  }
}
//无界调用判断
if (window.__POWERED_BY_WUJIE__) {
  console.log("acllllll");

  //设置对应的token
  let instance: any = null;
  window.__WUJIE_MOUNT = () => {
    instance = render();
  };
  window.__WUJIE_UNMOUNT = () => {
    if (instance) {
      instance.unmount();
      instance = null;
    }
  };
  window.__WUJIE.mount();
} else {
  render();
}
